    package com.edu.bhu.admin.controller.admin;

import java.util.List;

import com.edu.bhu.common.utils.DateUtils;
import com.edu.bhu.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.BikRepair;
import com.edu.bhu.admin.service.IBikRepairService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 报修记录Controller
 * 
 * @author heyinan
 * @date 2022-03-15
 */
@Controller
@RequestMapping("/admin/repair")
public class BikRepairController extends BaseController
{
    private String prefix = "admin/repair";

    @Autowired
    private IBikRepairService bikRepairService;

    @RequiresPermissions("admin:repair:view")
    @GetMapping()
    public String repair()
    {
        return prefix + "/repair";
    }

    /**
     * 打开我提交的报修记录列表
     */
    @RequiresPermissions("admin:repair:view")
    @GetMapping("/myRepair")
    public String myRepair()
    {
        return prefix + "/myRepair";
    }

    /**
     * 查询报修记录列表
     */
    @RequiresPermissions("admin:repair:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BikRepair bikRepair)
    {
        startPage();
        List<BikRepair> list = bikRepairService.selectBikRepairList(bikRepair);
        return getDataTable(list);
    }

    /**
     * 查询我的报修记录列表
     */
    @RequiresPermissions("admin:repair:list")
    @PostMapping("/myList")
    @ResponseBody
    public TableDataInfo myList(BikRepair bikRepair)
    {
        bikRepair.setUserId(ShiroUtils.getSysUser().getUserId());
        startPage();
        List<BikRepair> list = bikRepairService.selectBikRepairList(bikRepair);
        return getDataTable(list);
    }

    /**
     * 导出报修记录列表
     */
    @RequiresPermissions("admin:repair:export")
    @Log(title = "报修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BikRepair bikRepair)
    {
        List<BikRepair> list = bikRepairService.selectBikRepairList(bikRepair);
        ExcelUtil<BikRepair> util = new ExcelUtil<BikRepair>(BikRepair.class);
        return util.exportExcel(list, "报修记录数据");
    }

    /**
     * 新增报修记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报修记录
     */
    @RequiresPermissions("admin:repair:add")
    @Log(title = "报修记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BikRepair bikRepair)
    {
        //提交时间
        bikRepair.setSubTime(DateUtils.getNowDate());
        //用户ID
        bikRepair.setUserId(ShiroUtils.getSysUser().getUserId());
        return toAjax(bikRepairService.insertBikRepair(bikRepair));
    }

    /**
     * 修改报修记录
     */
    @RequiresPermissions("admin:repair:edit")
    @GetMapping("/edit/{repId}")
    public String edit(@PathVariable("repId") Long repId, ModelMap mmap)
    {
        BikRepair bikRepair = bikRepairService.selectBikRepairByRepId(repId);
        mmap.put("bikRepair", bikRepair);
        return prefix + "/edit";
    }

    /**
     * 修改保存报修记录
     */
    @RequiresPermissions("admin:repair:edit")
    @Log(title = "报修记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BikRepair bikRepair)
    {
        return toAjax(bikRepairService.updateBikRepair(bikRepair));
    }

    /**
     * 删除报修记录
     */
    @RequiresPermissions("admin:repair:remove")
    @Log(title = "报修记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bikRepairService.deleteBikRepairByRepIds(ids));
    }
}
